//
//  LGTCornerView.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/28.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit
enum CornerType:Int {
    case NonCornerType = 0
    case TopCornerType = 1
    case BottomCornerType = 2
    case TopLeftAndBottomRightCornerTypeType = 3
    case BottomRightCornerTypeType = 4
}

class LGTCornerView: UIView {
    var cornerSize:CGSize = CGSize.init(width: 0, height: 0)
    var type:CornerType = .NonCornerType
    var backColor:UIColor = UIColor.clear
    
    override func draw(_ rect: CGRect) {
        var bezierPath:UIBezierPath?
        if self.type == .NonCornerType{
            bezierPath = UIBezierPath.init(rect: rect)
        }else if self.type == .TopCornerType{
            bezierPath = UIBezierPath.init(roundedRect: rect, byRoundingCorners: UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue), cornerRadii: self.cornerSize)
        }else if self.type == .BottomCornerType{
            bezierPath = UIBezierPath.init(roundedRect: rect, byRoundingCorners: (UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomLeft.rawValue)), cornerRadii: self.cornerSize)
        }else if self.type == .TopLeftAndBottomRightCornerTypeType{
            bezierPath = UIBezierPath.init(roundedRect: rect, byRoundingCorners: (UIRectCorner(rawValue: UIRectCorner.topRight.rawValue | UIRectCorner.bottomRight.rawValue)), cornerRadii: self.cornerSize)
        }else if self.type == .BottomRightCornerTypeType{
            bezierPath = UIBezierPath.init(roundedRect: rect, byRoundingCorners: UIRectCorner.bottomRight, cornerRadii: self.cornerSize)
        }
        
        if bezierPath != nil{
            self.backColor.setFill()
            bezierPath!.fill()
        }
    }
}


